import { getToken, setToken, removeToken } from '@/utils/auth'

const state = {
  token: getToken(),
  name: ''
}

const mutations = {
  SET_TOKEN(state, token) {
    state.token = token
  },
  SET_NAME(state, name) {
    state.name = name
  }
}

const actions = {
  login({ commit }, userInfo) {
    commit('SET_NAME', userInfo.name)
    commit('SET_TOKEN', 'XX')
    setToken('XX')
  },
  resetToken({ commit }) {
    return new Promise(resolve => {
      commit('SET_TOKEN', '')
      removeToken()
      resolve()
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
